import 'package:mobx/mobx.dart';
import 'package:bookapp/api/http.dart';
import 'package:dio/dio.dart';
import 'package:bookapp/models/common.dart';


part 'home_store.g.dart';

class HomeStore = _HomeStore with _$HomeStore;

HomeStore $store = HomeStore();

abstract class _HomeStore with Store {
  @observable
  bool tile = false;
  @observable
  late CommonDataList recommendData;
  @observable
  late CommonDataList hotBooksData;
  @observable
  late CommonDataList popularBookData;
  @observable
  late VersionData versionData;


  @action
  void setTile(String key,dynamic value) {
    tile = value;
  }

// 首页数据
  @action
  Future getData() async {
    List<Response> response = await Future.wait([
      // 获取推荐
      HttpRequest().dio.get('/api/book_info/recommend',
          queryParameters: {"index": 1, "size": 10}),
      // 最受欢迎
      HttpRequest().dio.get('/api/book_info/popular_book?',
          queryParameters: {"index": 1, "size": 10}),
      // 最受欢迎
      HttpRequest().dio.get('/api/book_info/hot_book',
          queryParameters: {"index": 1, "size": 10}),
    ]);
    recommendData = CommonDataList.fromJson(response[0].data['data']);
    popularBookData = CommonDataList.fromJson(response[1].data['data']);
    hotBooksData = CommonDataList.fromJson(response[2].data['data']);
  }

  // 获取版本更新通知
  @action
  Future getVersion() async {
    print("---home store getversion");
    Response response = await HttpRequest().dio.get('/api/public/version');
    versionData = VersionData.fromJson(response.data);
    // versionData??=VersionData.formJson('');
  }
}